#ifndef TRANSACTION_H
#define TRANSACTION_H

#include <string>
#include <chrono>
#include <ctime>

namespace MiniBanking
{

    // Enum to represent the type of transaction
    enum class TransactionType
    {
        DEPOSIT,
        WITHDRAW,
        TRANSFER
    };

    /**
     * @brief Represents a single financial transaction record.
     */
    class Transaction
    {
    private:
        std::string transactionID_;
        TransactionType type_;
        double amount_;
        std::chrono::system_clock::time_point timestamp_;
        std::string sourceAccountID_;      // Empty if deposit
        std::string destinationAccountID_; // Empty if withdrawal
        std::string note_;

    public:
        /**
         * @brief Constructs a new Transaction object.
         * @param id Unique transaction ID.
         * @param type Type of the transaction (DEPOSIT, WITHDRAW, TRANSFER).
         * @param amount Transaction amount (always positive).
         * @param timestamp Time the transaction occurred.
         * @param sourceID Account ID initiating the transaction (e.g., withdrawing account, transferring account). Empty for deposits.
         * @param destID Account ID receiving the funds (e.g., depositing account, receiving account in transfer). Empty for withdrawals.
         * @param note Optional user-provided note.
         */
        Transaction(std::string id, TransactionType type, double amount,
                    std::chrono::system_clock::time_point timestamp,
                    std::string sourceID, std::string destID, std::string note);

        // --- Getters ---
        const std::string &getID() const;
        TransactionType getType() const;
        double getAmount() const;
        std::chrono::system_clock::time_point getTimestamp() const;
        const std::string &getSourceAccountID() const;
        const std::string &getDestinationAccountID() const;
        const std::string &getNote() const;

        // --- Operator Overload for Sorting ---
        /**
         * @brief Compares two transactions based on their timestamp for sorting.
         * @param other The other transaction to compare against.
         * @return True if this transaction occurred before the other.
         */
        bool operator<(const Transaction &other) const;

        // Default copy/move are acceptable as members are simple types or standard library objects
        Transaction(const Transaction &) = default;
        Transaction &operator=(const Transaction &) = default;
        Transaction(Transaction &&) = default;
        Transaction &operator=(Transaction &&) = default;
        ~Transaction() = default;
    };

    // Helper function to convert TransactionType enum to string (useful for display/reports)
    std::string transactionTypeToString(TransactionType type);

}

#endif
